// src/main/java/com/techchat/backend/service/MessageService.java

package com.techchat.backend.service;

import com.techchat.backend.mapper.MessageMapper;
import com.techchat.backend.model.Message;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MessageService {

    private final MessageMapper messageMapper;

    public MessageService(MessageMapper messageMapper) {
        this.messageMapper = messageMapper;
    }

    /**
     * 保存新消息到数据库
     */
    public void saveMessage(Message message) {
        messageMapper.insertMessage(message);
    }

    /**
     * 读取所有历史消息
     */
    public List<Message> getAllMessages() {
        return messageMapper.findAll();
    }
}
